/*
 * @Author: your name
 * @Date: 2020-07-23 22:09:30
 * @LastEditTime: 2020-07-24 23:33:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \react_app\src\store\reducer.js
 */
import {CHANGE_INPUT,ADD_TODO,INIT_TODO_LIST} from './actionType'
const defaultState = {
  inputValue : '请输入',
  todoList:[
    '8点公司开晨会分配今天的任务，总结昨天',
    '9点开项目需求会议',
    '10点修复昨天的bug问题',
    '11点做些开发工作预热'
  ]
}

const todeReducer = (state=defaultState,action)=>{

   switch (action.type) {
     case CHANGE_INPUT:
      // return {...state,inputValue:action.data}
        return Object.assign({},state,{inputValue:action.data})
      case ADD_TODO:
        //return {...state,inputValue:'',todoList:[action.data,...state.todoList]}
        var newTodo =JSON.parse(JSON.stringify(state.todoList))
        newTodo.unshift(action.data)
        return Object.assign({},state,{inputValue:'',todoList:newTodo})
      case INIT_TODO_LIST:
        return Object.assign({},state,{todoList:action.data})
     default:
       return state;
   }

 }


 export default todeReducer
